package com.fyx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fyx.config.FiveMongoConfig;
import com.fyx.config.FourthMongoConfig;
import com.fyx.entity.*;
import com.fyx.mapper.MonthInfoMapper;
import com.fyx.mapper.SysDictDetailMapper;
import com.fyx.service.IDayMonthService;
import com.fyx.until.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class DayMonthServiceImpl extends ServiceImpl<SysDictDetailMapper, SysDictDetail>  implements IDayMonthService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Resource(name = FourthMongoConfig.MONGO_TEMPLATE)
    private MongoTemplate fourthMongoTemplate;

    @Resource(name = FiveMongoConfig.MONGO_TEMPLATE)
    private MongoTemplate fiveMongoTemplate;

    @Autowired
    private MonthInfoMapper monthInfoMapper;


    @Override
    public Map advertDayData(DayDataEntity dayDataEntity, Pageable pageable){
        Query query = new Query();
        query.skip((pageable.getPageNumber())*pageable.getPageSize());
        query.limit(pageable.getPageSize());
        Criteria criteria = new Criteria();
        if (dayDataEntity.getQTime()!=null){
            criteria.and("time").gte(dayDataEntity.getQTime().get(0).getTime()/1000).lte(dayDataEntity.getQTime().get(1).getTime()/1000);
        }
        criteria.and("channel").is("total");
        query.addCriteria(criteria);
        query.with( Sort.by(Sort.Direction.DESC,new String[]{"time"}));
        List<DayDataEntity> list = mongoTemplate.find(query, DayDataEntity.class);
        long total = mongoTemplate.count(query, DayDataEntity.class);
        List list2=new ArrayList();
        if(list.size()>0){
            for (DayDataEntity dayDataEntity1:list){
                criteria=new Criteria();
                query=new Query();
                criteria.and("channel").ne("total");
                criteria.and("time").is(dayDataEntity1.getTime());
                query.addCriteria(criteria);
                List<DayDataEntity> list1 = mongoTemplate.find(query, DayDataEntity.class);
                Map map1=new HashMap();
                map1.put("time",dayDataEntity1.getTime());
                map1.put("channel",dayDataEntity1.getChannel());
                for (DayDataEntity dayDataEntity2:list1){
                   if(dayDataEntity2.getChannel().equals("hzmjxl_total")){
                       map1.put("xx_qq",dayDataEntity2.getPangolin());
                       map1.put("xx_wx",dayDataEntity2.getYoulianghui());
                       map1.put("xx_mmy",dayDataEntity2.getMmy());
                       map1.put("xx_7k7k",dayDataEntity2.getSevenk());
                       map1.put("xx_iqiyiH5",dayDataEntity2.getIqiyiH5());
                       map1.put("xx_douyin",dayDataEntity2.getDouyin());
                   }
                   else if(dayDataEntity2.getChannel().equals("hcmjxl_total")){
                       map1.put("hc_wx",dayDataEntity2.getYoulianghui());
                       map1.put("hc_oppoH5",dayDataEntity2.getOppoH5());
                       map1.put("hc_official",dayDataEntity2.getLfjpay());
                       map1.put("hc_iOS",dayDataEntity2.getIOS());
                       map1.put("hc_huawei",dayDataEntity2.getHuawei());
                       map1.put("hc_mi",dayDataEntity2.getMi());
                       map1.put("hc_vivo",dayDataEntity2.getVivo());
                       map1.put("hc_vivoad",dayDataEntity2.getVivoAd());
                       map1.put("hc_oppo",dayDataEntity2.getOppo());
                       map1.put("hc_chuanshanjia",dayDataEntity2.getChuanshanjia());
                   }
                   else if(dayDataEntity2.getChannel().equals("zhsmjcl_total")) {
                       map1.put("zs_douyin",dayDataEntity2.getDouyin());
                       map1.put("zs_wx",dayDataEntity2.getYoulianghui());
                   }
                   else if(dayDataEntity2.getChannel().equals("gdmjxl_total")){
                       map1.put("gd_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("jzmjxl_total")){
                       map1.put("jz_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("zzmjxl_total")){
                       map1.put("zz_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("fymjxl_total")){
                       map1.put("fy_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("lhmjxl_total")){
                       map1.put("lh_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("jhmjxl_total")){
                       map1.put("jh_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("pamjcl_total")){
                       map1.put("pa_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("txmjcl_total")){
                       map1.put("tx_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("ykmjcl_total")){
                       map1.put("yk_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("ccmjcl_total")){
                       map1.put("cc_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("zsmjcl_total")){
                       map1.put("zhs_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("kldmjcl_total")){
                       map1.put("kld_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("mmmjxl_total")){
                       map1.put("mm_wx",dayDataEntity2.getYoulianghui());
                   }else if(dayDataEntity2.getChannel().equals("gdmjcl_total")){
                       map1.put("gdcl_qq",dayDataEntity2.getPangolin());
                   }
                }
                list2.add(map1);

            }
        }
        Map map =new HashMap();
        map.put("list",list2);
        map.put("total",total);
        return map;
    }

    @Override
    public Map dayData(DayDataEntity dayDataEntity, Pageable pageable) {
        Query query = new Query();
        query.skip((pageable.getPageNumber())*pageable.getPageSize());
        query.limit(pageable.getPageSize());
        boolean re_flag=true;
        if(dayDataEntity.getChannel().equals("total1")){
            dayDataEntity.setChannel("total");
            re_flag=false;
        }
        Criteria criteria = new Criteria();
        if (dayDataEntity.getQTime()!=null){
            criteria.andOperator(
               Criteria.where("time").gte(dayDataEntity.getQTime().get(0).getTime()/1000).lte(dayDataEntity.getQTime().get(1).getTime()/1000)
            );
        }
        if(StringUtils.isNotBlank(dayDataEntity.getChannel())) {
            if(dayDataEntity.getChannel().equals("total")) {
                criteria.orOperator(Criteria.where("channel").is(dayDataEntity.getChannel()), Criteria.where("channel").exists(false));
            }else {
                criteria.and("channel").is(dayDataEntity.getChannel());
            }
        }
        else {
            criteria.and("channel").ne("total");
        }
        query.addCriteria(criteria);
        query.with( Sort.by(Sort.Direction.DESC,new String[]{"time"}));
        List<DayDataEntity> list = mongoTemplate.find(query, DayDataEntity.class);
        long total = mongoTemplate.count(query, DayDataEntity.class);
        if(list.size()>0&&dayDataEntity.getChannel()!=null&&(dayDataEntity.getChannel().equals("total")||dayDataEntity.getChannel().equals("totalcl"))){
            for (DayDataEntity dayDataEntity1:list){
                String[] strArray={"0","0","0","0","0","0","0"};
                dayDataEntity1.setXxmj(strArray);
                dayDataEntity1.setGdmj(strArray);
                dayDataEntity1.setHcmj(strArray);
                dayDataEntity1.setZsmj(strArray);
                dayDataEntity1.setZzmj(strArray);
                dayDataEntity1.setJzmj(strArray);
                dayDataEntity1.setFymj(strArray);
                dayDataEntity1.setLhmj(strArray);
                dayDataEntity1.setJhmj(strArray);
                dayDataEntity1.setPamj(strArray);
                dayDataEntity1.setTxmj(strArray);
                dayDataEntity1.setYkmj(strArray);
                dayDataEntity1.setZhsmj(strArray);
                dayDataEntity1.setCgmj(strArray);
                dayDataEntity1.setQcmj(strArray);
                dayDataEntity1.setKldmj(strArray);
                dayDataEntity1.setMmmj(strArray);
                dayDataEntity1.setXxcl(strArray);
                dayDataEntity1.setGdcl(strArray);
                criteria = new Criteria();
                query = new Query();
                criteria.and("time").is(dayDataEntity1.getTime());
                criteria.and("channel").ne("total");
                query.addCriteria(criteria);
                List<DayDataEntity> list1 = mongoTemplate.find(query, DayDataEntity.class);
                if(list1.size()>0) {
                    for (DayDataEntity dayDataEntity2 : list1) {
                        if(re_flag&&dayDataEntity2.getChannel().equals("totalcl")&&dayDataEntity1.getChannel().equals("total")){
                            dayDataEntity1.setAllMoney(dayDataEntity1.getAllMoney()+dayDataEntity2.getAllMoney());
                            dayDataEntity1.setDayActivity(dayDataEntity1.getDayActivity()+dayDataEntity2.getDayActivity());
                            dayDataEntity1.setNewUserCount(dayDataEntity1.getNewUserCount()+dayDataEntity2.getNewUserCount());
                        }
                        if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("hcmjxl_total")){
                            strArray=new String[85];
                            strArray[0]=dayDataEntity2.getQqMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[2]=dayDataEntity2.getMeituanPay().toString();
                            strArray[3]=dayDataEntity2.getMeituanRePay().toString();
                            strArray[4]=dayDataEntity2.getOppoPay().toString();
                            strArray[5]=dayDataEntity2.getIqiyiPay().toString();
                            strArray[6]=dayDataEntity2.getSwjoyPay().toString();
                            strArray[7]=dayDataEntity2.getSdwpay().toString();
                            strArray[8]=dayDataEntity2.getJdPay().toString();
                            strArray[9]=dayDataEntity2.getZhongcaipay().toString();
                         //   strArray[10]=dayDataEntity2.getYouliaopay().toString();
                            strArray[11]=dayDataEntity2.getHuaweipay().toString();
                            strArray[12]=dayDataEntity2.getMipay().toString();
                            strArray[13]=dayDataEntity2.getVivoPay().toString();
                            strArray[14]=dayDataEntity2.getVivoAdPay().toString();
                            strArray[15]=dayDataEntity2.getOppoMbPay().toString();

                            strArray[16]=dayDataEntity2.getPangolin().toString();
                            strArray[17]=dayDataEntity2.getYoulianghui().toString();
                            strArray[18]=dayDataEntity2.getOppoH5().toString();
                            strArray[19]=dayDataEntity2.getChuanshanjia().toString();
                            strArray[20]=dayDataEntity2.getIOS().toString();
                            strArray[21]=dayDataEntity2.getHuawei().toString();
                            strArray[22]=dayDataEntity2.getMi().toString();
                            strArray[23]=dayDataEntity2.getVivo().toString();
                            strArray[24]=dayDataEntity2.getVivoAd().toString();
                            strArray[25]=dayDataEntity2.getOppo().toString();

                            strArray[26]=dayDataEntity2.getQqActivity()+"";
                            strArray[27]=dayDataEntity2.getWxActivity()+"";
                            strArray[28]=dayDataEntity2.getMeituanActivity()+"";
                            strArray[29]=dayDataEntity2.getMeituanReActivity()+"";
                            strArray[30]=dayDataEntity2.getOppoActivity()+"";
                            strArray[31]=dayDataEntity2.getIqiyiActivity()+"";
                            strArray[32]=dayDataEntity2.getSwjoyActivity()+"";
                            strArray[33]=dayDataEntity2.getSdwActivity()+"";
                            strArray[34]=dayDataEntity2.getJdActivity()+"";
                            strArray[35]=dayDataEntity2.getZhongcaiActivity()+"";
                        //    strArray[36]=dayDataEntity2.getYouliaoActivity()+"";
                            strArray[37]=dayDataEntity2.getHuaweiActivity()+"";
                            strArray[38]=dayDataEntity2.getMiActivity()+"";
                            strArray[39]=dayDataEntity2.getVivoActivity()+"";
                            strArray[40]=dayDataEntity2.getVivoAdActivity()+"";
                            strArray[41]=dayDataEntity2.getOppoMbActivity()+"";

                            strArray[42]=dayDataEntity2.getQqUserCount()+"";
                            strArray[43]=dayDataEntity2.getWxUserCount()+"";
                            strArray[44]=dayDataEntity2.getMeituanUserCount()+"";
                            strArray[45]=dayDataEntity2.getMeituanReUserCount()+"";
                            strArray[46]=dayDataEntity2.getOppoUserCount()+"";
                            strArray[47]=dayDataEntity2.getIqiyiUserCount()+"";
                            strArray[48]=dayDataEntity2.getSwjoyUserCount()+"";
                            strArray[49]=dayDataEntity2.getSdwUserCount()+"";
                            strArray[50]=dayDataEntity2.getJdUserCount()+"";
                            strArray[51]=dayDataEntity2.getZhongcaiUserCount()+"";
                        //    strArray[52]=dayDataEntity2.getYouliaoUserCount()+"";
                            strArray[53]=dayDataEntity2.getHuaweiUserCount()+"";
                            strArray[54]=dayDataEntity2.getMiUserCount()+"";
                            strArray[55]=dayDataEntity2.getVivoUserCount()+"";
                            strArray[56]=dayDataEntity2.getVivoAdUserCount()+"";
                            strArray[57]=dayDataEntity2.getOppoMbUserCount()+"";

                     //       strArray[58]=dayDataEntity2.getA2345pay()+"";
                            strArray[59]=dayDataEntity2.getXunleipay()+"";
                            strArray[60]=dayDataEntity2.getBaidupay()+"";
                        //    strArray[61]=dayDataEntity2.getA2345Activity()+"";
                            strArray[62]=dayDataEntity2.getXunleiActivity()+"";
                         //   strArray[63]=dayDataEntity2.getBaiduActivity()+"";
                        //    strArray[64]=dayDataEntity2.getA2345UserCount()+"";
                            strArray[65]=dayDataEntity2.getXunleiUserCount()+"";
                      //      strArray[66]=dayDataEntity2.getBaiduUserCount()+"";
                      //      strArray[67]=dayDataEntity2.getBaiduIospay()+"";
                            strArray[68]=dayDataEntity2.getDouyinActivity()+"";
                            strArray[69]=dayDataEntity2.getDouyinUserCount()+"";

                            strArray[70]=dayDataEntity2.getTvhuanpay()+"";
                            strArray[71]=dayDataEntity2.getTvcoocaapay()+"";
                            strArray[72]=dayDataEntity2.getTvhisensepay()+"";
                            strArray[73]=dayDataEntity2.getMmypay()+"";
                            strArray[74]=dayDataEntity2.getTvhuanActivity()+"";
                            strArray[75]=dayDataEntity2.getTvcoocaaActivity()+"";
                            strArray[76]=dayDataEntity2.getTvhisenseActivity()+"";
                            strArray[77]=dayDataEntity2.getMmyActivity()+"";
                            strArray[78]=dayDataEntity2.getTvhuanUserCount()+"";
                            strArray[79]=dayDataEntity2.getTvcoocaaUserCount()+"";
                            strArray[80]=dayDataEntity2.getTvhisenseUserCount()+"";
                            strArray[81]=dayDataEntity2.getMmyUserCount()+"";
                            strArray[82]=dayDataEntity2.getMilanbarpay().toString();
                            strArray[83]=dayDataEntity2.getMilanbarActivity()+"";
                            strArray[84]=dayDataEntity2.getMilanbarUserCount()+"";
                            dayDataEntity1.setHcmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("zhsmjcl_total")){
                            strArray=new String[4];
                            try {
                                strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                                strArray[1]=dayDataEntity2.getWxActivity()+"";
                                strArray[2]=dayDataEntity2.getWxUserCount()+"";
                                strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            }        catch (Exception ex){
                                strArray[0]="0";
                                strArray[1]="0";
                                strArray[2]="0";
                                strArray[3]="0";
                            }
                            dayDataEntity1.setZsmj(strArray);
                        }
                        else  if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("hzmjxl_total")){
                                strArray=new String[82];
                            strArray[0]=dayDataEntity2.getQqMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[2]=dayDataEntity2.getMeituanPay().toString();
                            strArray[3]=dayDataEntity2.getMeituanRePay().toString();
                            strArray[4]=dayDataEntity2.getOppoPay().toString();
                            strArray[5]=dayDataEntity2.getIqiyiPay().toString();
                            strArray[6]=dayDataEntity2.getSwjoyPay().toString();
                            strArray[7]=dayDataEntity2.getSdwpay().toString();
                            strArray[8]=dayDataEntity2.getJdPay().toString();
                            strArray[9]=dayDataEntity2.getBytedancepay().toString();
                            strArray[10]=dayDataEntity2.getHuaweih5pay().toString();
                            strArray[11]=dayDataEntity2.getSevenk().toString();
                            strArray[12]=dayDataEntity2.getSevenkpay().toString();
                            strArray[13]=dayDataEntity2.getSevenkActivity()+"";
                            strArray[14]=dayDataEntity2.getSevenkUserCount()+"";
                            strArray[15]=dayDataEntity2.getOppoMbPay().toString();

                            strArray[16]=dayDataEntity2.getPangolin().toString();
                            strArray[17]=dayDataEntity2.getYoulianghui().toString();
                            strArray[18]=dayDataEntity2.getOppoH5().toString();
                            strArray[19]=dayDataEntity2.getChuanshanjia().toString();
                            strArray[20]=dayDataEntity2.getDouyin().toString();
                            strArray[21]=dayDataEntity2.getHuawei().toString();
                            strArray[22]=dayDataEntity2.getMi().toString();
                            strArray[23]=dayDataEntity2.getVivo().toString();
                            strArray[24]=dayDataEntity2.getVivoAd().toString();
                            strArray[25]=dayDataEntity2.getOppo().toString();

                            strArray[26]=dayDataEntity2.getQqActivity()+"";
                            strArray[27]=dayDataEntity2.getWxActivity()+"";
                            strArray[28]=dayDataEntity2.getMeituanActivity()+"";
                            strArray[29]=dayDataEntity2.getMeituanReActivity()+"";
                            strArray[30]=dayDataEntity2.getHuaweiH5Activity()+"";
                            strArray[31]=dayDataEntity2.getIqiyiActivity()+"";
                            strArray[32]=dayDataEntity2.getSwjoyActivity()+"";
                            strArray[33]=dayDataEntity2.getSdwActivity()+"";
                            strArray[34]=dayDataEntity2.getJdActivity()+"";
                            strArray[35]=dayDataEntity2.getIqiyih5pay()+"";
                            strArray[36]=dayDataEntity2.getIqiyih5Activity()+"";
                            strArray[37]=dayDataEntity2.getIqiyih5UserCount()+"";
                            strArray[38]=dayDataEntity2.getLfjpay()+"";
                            strArray[39]=dayDataEntity2.getLfjActivity()+"";
                            strArray[40]=dayDataEntity2.getLfjUserCount()+"";
                            strArray[41]=dayDataEntity2.getBytedanceActivity()+"";

                            strArray[42]=dayDataEntity2.getQqUserCount()+"";
                            strArray[43]=dayDataEntity2.getWxUserCount()+"";
                            strArray[44]=dayDataEntity2.getMeituanUserCount()+"";
                            strArray[45]=dayDataEntity2.getMeituanReUserCount()+"";
                            strArray[46]=dayDataEntity2.getHuaweiH5UserCount()+"";
                            strArray[47]=dayDataEntity2.getIqiyiUserCount()+"";
                            strArray[48]=dayDataEntity2.getSwjoyUserCount()+"";
                            strArray[49]=dayDataEntity2.getSdwUserCount()+"";
                            strArray[50]=dayDataEntity2.getJdUserCount()+"";
                            strArray[51]=dayDataEntity2.getCaipiaopay()+"";
                            strArray[52]=dayDataEntity2.getCaipiaoActivity()+"";
                            strArray[53]=dayDataEntity2.getCaipiaoUserCount()+"";
                            strArray[54]=dayDataEntity2.getMiUserCount()+"";
                            strArray[55]=dayDataEntity2.getVivoUserCount()+"";
                            strArray[56]=dayDataEntity2.getVivoAdUserCount()+"";
                            strArray[57]=dayDataEntity2.getBytedanceUserCount()+"";

                            strArray[58]=dayDataEntity2.getAlipay()+"";
                            strArray[59]=dayDataEntity2.getXunleipay()+"";
                            strArray[60]=dayDataEntity2.getAliActivity()+"";
                            strArray[61]=dayDataEntity2.getAliUserCount()+"";
                            strArray[62]=dayDataEntity2.getXunleiActivity()+"";
                            strArray[63]="";
                            strArray[64]="";
                            strArray[65]=dayDataEntity2.getXunleiUserCount()+"";
                            strArray[66]="";
                            strArray[67]=dayDataEntity2.getBytedancepay()+"";
                            strArray[68]=dayDataEntity2.getBytedanceActivity()+"";
                            strArray[69]=dayDataEntity2.getBytedanceUserCount()+"";

                            strArray[70]=dayDataEntity2.getTvhuanpay()+"";
                            strArray[71]=dayDataEntity2.getTvcoocaapay()+"";
                            strArray[72]=dayDataEntity2.getTvhisensepay()+"";
                            strArray[73]=dayDataEntity2.getMmypay()+"";
                            strArray[74]=dayDataEntity2.getTvhuanActivity()+"";
                            strArray[75]=dayDataEntity2.getTvcoocaaActivity()+"";
                            strArray[76]=dayDataEntity2.getTvhisenseActivity()+"";
                            strArray[77]=dayDataEntity2.getMmyActivity()+"";
                            strArray[78]=dayDataEntity2.getTvhuanUserCount()+"";
                            strArray[79]=dayDataEntity2.getTvcoocaaUserCount()+"";
                            strArray[80]=dayDataEntity2.getTvhisenseUserCount()+"";
                            strArray[81]=dayDataEntity2.getMmyUserCount()+"";
                           dayDataEntity1.setXxmj(strArray);
                        }
                        else  if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("gdmjxl_total")){
                                strArray=new String[82];
                            strArray[0]=dayDataEntity2.getQqMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[2]=dayDataEntity2.getMeituanPay().toString();
                            strArray[3]=dayDataEntity2.getMeituanRePay().toString();
                            strArray[4]=dayDataEntity2.getOppoPay().toString();
                            strArray[5]=dayDataEntity2.getIqiyiPay().toString();
                            strArray[6]=dayDataEntity2.getSwjoyPay().toString();
                            strArray[7]=dayDataEntity2.getSdwpay().toString();
                            strArray[8]=dayDataEntity2.getJdPay().toString();
                            strArray[9]=dayDataEntity2.getQihoopay().toString();
                            strArray[10]=dayDataEntity2.getApplepay().toString();
                            strArray[11]=dayDataEntity2.getHuaweipay().toString();
                            strArray[12]=dayDataEntity2.getMipay().toString();
                            strArray[13]=dayDataEntity2.getVivoPay().toString();
                            strArray[14]=dayDataEntity2.getVivoAdPay().toString();
                            strArray[15]=dayDataEntity2.getOppoMbPay().toString();

                            strArray[16]=dayDataEntity2.getPangolin().toString();
                            strArray[17]=dayDataEntity2.getYoulianghui().toString();
                            strArray[18]=dayDataEntity2.getOppoH5().toString();
                            strArray[19]=dayDataEntity2.getChuanshanjia().toString();
                            strArray[20]=dayDataEntity2.getIOS().toString();
                            strArray[21]=dayDataEntity2.getHuawei().toString();
                            strArray[22]=dayDataEntity2.getMi().toString();
                            strArray[23]=dayDataEntity2.getVivo().toString();
                            strArray[24]=dayDataEntity2.getVivoAd().toString();
                            strArray[25]=dayDataEntity2.getOppo().toString();

                            strArray[26]=dayDataEntity2.getQqActivity()+"";
                            strArray[27]=dayDataEntity2.getWxActivity()+"";
                            strArray[28]=dayDataEntity2.getMeituanActivity()+"";
                            strArray[29]=dayDataEntity2.getMeituanReActivity()+"";
                            strArray[30]=dayDataEntity2.getOppoActivity()+"";
                            strArray[31]=dayDataEntity2.getIqiyiActivity()+"";
                            strArray[32]=dayDataEntity2.getSwjoyActivity()+"";
                            strArray[33]=dayDataEntity2.getSdwActivity()+"";
                            strArray[34]=dayDataEntity2.getJdActivity()+"";
                            strArray[35]=dayDataEntity2.getQihooActivity()+"";
                            strArray[36]=dayDataEntity2.getAppleActivity()+"";
                            strArray[37]=dayDataEntity2.getHuaweiActivity()+"";
                            strArray[38]=dayDataEntity2.getMiActivity()+"";
                            strArray[39]=dayDataEntity2.getVivoActivity()+"";
                            strArray[40]=dayDataEntity2.getVivoAdActivity()+"";
                            strArray[41]=dayDataEntity2.getOppoMbActivity()+"";

                            strArray[42]=dayDataEntity2.getQqUserCount()+"";
                            strArray[43]=dayDataEntity2.getWxUserCount()+"";
                            strArray[44]=dayDataEntity2.getMeituanUserCount()+"";
                            strArray[45]=dayDataEntity2.getMeituanReUserCount()+"";
                            strArray[46]=dayDataEntity2.getOppoUserCount()+"";
                            strArray[47]=dayDataEntity2.getIqiyiUserCount()+"";
                            strArray[48]=dayDataEntity2.getSwjoyUserCount()+"";
                            strArray[49]=dayDataEntity2.getSdwUserCount()+"";
                            strArray[50]=dayDataEntity2.getJdUserCount()+"";
                            strArray[51]=dayDataEntity2.getQihooUserCount()+"";
                            strArray[52]=dayDataEntity2.getAppleUserCount()+"";
                            strArray[53]=dayDataEntity2.getHuaweiUserCount()+"";
                            strArray[54]=dayDataEntity2.getMiUserCount()+"";
                            strArray[55]=dayDataEntity2.getVivoUserCount()+"";
                            strArray[56]=dayDataEntity2.getVivoAdUserCount()+"";
                            strArray[57]=dayDataEntity2.getOppoMbUserCount()+"";

                            strArray[58]="";
                            strArray[59]=dayDataEntity2.getXunleipay()+"";
                            strArray[60]=dayDataEntity2.getBaidupay()+"";
                            strArray[61]="";
                            strArray[62]=dayDataEntity2.getXunleiActivity()+"";
                            strArray[63]="";
                            strArray[64]="";
                            strArray[65]=dayDataEntity2.getXunleiUserCount()+"";
                            strArray[66]="";
                            strArray[67]=dayDataEntity2.getDouyinpay()+"";
                            strArray[68]=dayDataEntity2.getDouyinActivity()+"";
                            strArray[69]=dayDataEntity2.getDouyinUserCount()+"";

                            strArray[70]=dayDataEntity2.getTvhuanpay()+"";
                            strArray[71]=dayDataEntity2.getTvcoocaapay()+"";
                            strArray[72]=dayDataEntity2.getTvhisensepay()+"";
                            strArray[73]=dayDataEntity2.getMmypay()+"";
                            strArray[74]=dayDataEntity2.getTvhuanActivity()+"";
                            strArray[75]=dayDataEntity2.getTvcoocaaActivity()+"";
                            strArray[76]=dayDataEntity2.getTvhisenseActivity()+"";
                            strArray[77]=dayDataEntity2.getMmyActivity()+"";
                            strArray[78]=dayDataEntity2.getTvhuanUserCount()+"";
                            strArray[79]=dayDataEntity2.getTvcoocaaUserCount()+"";
                            strArray[80]=dayDataEntity2.getTvhisenseUserCount()+"";
                            strArray[81]=dayDataEntity2.getMmyUserCount()+"";
                            dayDataEntity1.setGdmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("jzmjxl_total")){
                            strArray=new String[4];
                            strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxActivity()+"";
                            strArray[2]=dayDataEntity2.getWxUserCount()+"";
                            strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            dayDataEntity1.setJzmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("zzmjxl_total")){
                            strArray=new String[4];
                            strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxActivity()+"";
                            strArray[2]=dayDataEntity2.getWxUserCount()+"";
                            strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            dayDataEntity1.setZzmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("fymjxl_total")){
                            strArray=new String[4];
                            strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxActivity()+"";
                            strArray[2]=dayDataEntity2.getWxUserCount()+"";
                            strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            dayDataEntity1.setFymj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("lhmjxl_total")){
                            strArray=new String[4];
                            strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxActivity()+"";
                            strArray[2]=dayDataEntity2.getWxUserCount()+"";
                            strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            dayDataEntity1.setLhmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("jhmjxl_total")){
                            strArray=new String[4];
                            strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxActivity()+"";
                            strArray[2]=dayDataEntity2.getWxUserCount()+"";
                            strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            dayDataEntity1.setJhmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("pamjcl_total")){
                            strArray=new String[4];
                            strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxActivity()+"";
                            strArray[2]=dayDataEntity2.getWxUserCount()+"";
                            strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            dayDataEntity1.setPamj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("txmjcl_total")){
                            strArray=new String[4];
                            strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxActivity()+"";
                            strArray[2]=dayDataEntity2.getWxUserCount()+"";
                            strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            dayDataEntity1.setTxmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("ykmjcl_total")){
                            strArray=new String[4];
                            strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxActivity()+"";
                            strArray[2]=dayDataEntity2.getWxUserCount()+"";
                            strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            dayDataEntity1.setYkmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("zsmjcl_total")){
                            strArray=new String[4];
                            strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                            strArray[1]=dayDataEntity2.getWxActivity()+"";
                            strArray[2]=dayDataEntity2.getWxUserCount()+"";
                            strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            dayDataEntity1.setZhsmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("cgmjxl_total")){
                            strArray=new String[4];
                            try {
                                strArray[0]=dayDataEntity2.getShengyepay().toString();
                            strArray[1]=dayDataEntity2.getShengyeActivity()+"";
                            strArray[2]=dayDataEntity2.getShengyeUserCount()+"";
                            strArray[3]="0";
                            }
                            catch (Exception ex){
                                strArray[0]="0";
                                strArray[1]="0";
                                strArray[2]="0";
                                strArray[3]="0";
                            }
                            dayDataEntity1.setCgmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("gdmjxl_app_total")){

                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("kldmjcl_total")){
                            strArray=new String[4];
                            try {
                                strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                                strArray[1]=dayDataEntity2.getWxActivity()+"";
                                strArray[2]=dayDataEntity2.getWxUserCount()+"";
                                strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            }        catch (Exception ex){
                                strArray[0]="0";
                                strArray[1]="0";
                                strArray[2]="0";
                                strArray[3]="0";
                            }
                            dayDataEntity1.setKldmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("mmmjxl_total")){
                            strArray=new String[4];
                            try {
                                strArray[0]=dayDataEntity2.getWxMiniGamePay().toString();
                                strArray[1]=dayDataEntity2.getWxActivity()+"";
                                strArray[2]=dayDataEntity2.getWxUserCount()+"";
                                strArray[3]=dayDataEntity2.getYoulianghui()+"";
                            }        catch (Exception ex){
                                strArray[0]="0";
                                strArray[1]="0";
                                strArray[2]="0";
                                strArray[3]="0";
                            }
                            dayDataEntity1.setMmmj(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("xxmjcl_total")){
                            strArray=new String[8];
                            try {
                                strArray[0]=dayDataEntity2.getZuiyoupay().toString();
                                strArray[1]=dayDataEntity2.getZuiyouActivity()+"";
                                strArray[2]=dayDataEntity2.getZuiyouUserCount()+"";
                                strArray[3]="0";
                                strArray[4]=dayDataEntity2.getXunleipay().toString();
                                strArray[5]=dayDataEntity2.getXunleiActivity()+"";
                                strArray[6]=dayDataEntity2.getXunleiUserCount()+"";
                                strArray[7]="0";
                            }        catch (Exception ex){
                                strArray[0]="0";
                                strArray[1]="0";
                                strArray[2]="0";
                                strArray[3]="0";
                                strArray[4]="0";
                                strArray[5]="0";
                                strArray[6]="0";
                                strArray[7]="0";
                            }
                            dayDataEntity1.setXxcl(strArray);
                        }
                        else if(dayDataEntity2.getChannel()!=null&&dayDataEntity2.getChannel().equals("gdmjcl_total")){
                            strArray=new String[4];
                            try {
                                strArray[0]=dayDataEntity2.getQqMiniGamePay().toString();
                                strArray[1]=dayDataEntity2.getQqActivity()+"";
                                strArray[2]=dayDataEntity2.getQqUserCount()+"";
                                strArray[3]=dayDataEntity2.getPangolin()+"";
                            }        catch (Exception ex){
                                strArray[0]="0";
                                strArray[1]="0";
                                strArray[2]="0";
                                strArray[3]="0";
                            }
                            dayDataEntity1.setGdcl(strArray);
                        }
                    }
                }
            }
        }

        Map map =new HashMap();
        map.put("list",list);
        map.put("total",total);
        return map;
    }

    @Override
    public void updatePangolin(StaticeEntity staticeEntity) {
        //DayDataEntity dayDataEntity=(DayDataEntity)staticeEntity.getV10();
        System.out.println(staticeEntity);
        String channel="hzmjxl_total";
        Integer time=staticeEntity.getV1();
        String flag=staticeEntity.getV6().split("_")[1];
        switch (staticeEntity.getV6().split("_")[0]){
            case "xx":
                channel="hzmjxl_total";
                break;
            case "gd":
                channel="gdmjxl_total";
                break;
            case "hc":
                channel="hcmjxl_total";
                break;
            case "jz":
                channel="jzmjxl_total";
                break;
            case "zz":
                channel="zzmjxl_total";
                break;
            case "zs":
                channel="zhsmjcl_total";
                break;
            case "fy":
                channel="fymjxl_total";
                break;
            case "lh":
                channel="lhmjxl_total";
                break;
            case "jh":
                channel="jhmjxl_total";
                break;
            case "pa":
                channel="pamjcl_total";
                break;
            case "tx":
                channel="txmjcl_total";
                break;
            case "yk":
                channel="ykmjcl_total";
                break;
            case "zhs":
                channel="zsmjcl_total";
                break;
            case "xxcl":
                channel="xxmjcl_total";
                break;
            case "gdcl":
                channel="gdmjcl_total";
                break;
            case "kld":
                channel="kldmjcl_total";
                break;
            case "mm":
                channel="mmmjxl_total";
                break;
            }

       // System.out.println("channel is=========="+channel);
        Criteria criteria=new Criteria();
        criteria.and("time").is(time);
        criteria.and("channel").is(channel);
        DayDataEntity dayDataEntity1= mongoTemplate.findOne(new Query().addCriteria(criteria),DayDataEntity.class);
     //   System.out.println("dayDataEntity1 is=========="+dayDataEntity1);
        Query query=new Query();
        criteria=new Criteria();
        if(channel.indexOf("cl_")>0){
           criteria.and("channel").is("totalcl");
        }else {
            criteria.and("channel").is("total");
        }
        criteria.and("time").is(dayDataEntity1.getTime());
         query.addCriteria(criteria);
        DayDataEntity dayDataEntityCount= mongoTemplate.findOne(query,DayDataEntity.class);
        Update update = new Update();
        Update update1 = new Update();
        if(flag.equals("pangolin")){
            update1.set(flag,dayDataEntityCount.getPangolin()-dayDataEntity1.getPangolin()+staticeEntity.getV9());
            update.set(flag,staticeEntity.getV9());
        }
        else if(flag.equals("youlianghui")){
            update1.set(flag,dayDataEntityCount.getYoulianghui()-dayDataEntity1.getYoulianghui()+staticeEntity.getV9());

            update.set(flag,staticeEntity.getV9());
        }
        else if(flag.equals("vivo")){
            update1.set(flag,dayDataEntityCount.getVivo()-dayDataEntity1.getVivo()+staticeEntity.getV9());

            update.set(flag,staticeEntity.getV9());
        }
       else if(flag.equals("vivoAd")){
            update1.set(flag,dayDataEntityCount.getVivoAd()-dayDataEntity1.getVivoAd()+staticeEntity.getV9());

            update.set(flag,staticeEntity.getV9());
        }
        else if(flag.equals("mi")){
            update1.set(flag,dayDataEntityCount.getMi()-dayDataEntity1.getMi()+staticeEntity.getV9());

            update.set(flag,staticeEntity.getV9());
        }
        else if(flag.equals("huawei")){
            update1.set(flag,dayDataEntityCount.getHuawei()-dayDataEntity1.getHuawei()+staticeEntity.getV9());

            update.set(flag,staticeEntity.getV9());
        }else if(flag.equals("iOS")){
            update1.set(flag,dayDataEntityCount.getIOS()-dayDataEntity1.getIOS()+staticeEntity.getV9());
            update.set(flag,staticeEntity.getV9());
        }else if(flag.equals("oppoH5")){
            update1.set(flag,dayDataEntityCount.getOppoH5()-dayDataEntity1.getOppoH5()+staticeEntity.getV9());
            update.set(flag,staticeEntity.getV9());
        }else if(flag.equals("oppo")){
            update1.set(flag,dayDataEntityCount.getOppo()-dayDataEntity1.getOppo()+staticeEntity.getV9());
            update.set(flag,staticeEntity.getV9());
        }else if(flag.equals("chuanshanjia")){
            update1.set(flag,dayDataEntityCount.getChuanshanjia()-dayDataEntity1.getChuanshanjia()+staticeEntity.getV9());
            update.set(flag,staticeEntity.getV9());
        }else if(flag.equals("douyin")){
            update1.set(flag,dayDataEntityCount.getDouyin()-dayDataEntity1.getDouyin()+staticeEntity.getV9());
            update.set(flag,staticeEntity.getV9());
        }else if(flag.equals("sevenk")){
            update1.set(flag,dayDataEntityCount.getSevenk()-dayDataEntity1.getSevenk()+staticeEntity.getV9());
            update.set(flag,staticeEntity.getV9());
        }else if(flag.equals("mmy")){
            update1.set(flag,dayDataEntityCount.getMmy()-dayDataEntity1.getMmy()+staticeEntity.getV9());
            update.set(flag,staticeEntity.getV9());
        }else if(flag.equals("iqiyiH5")){
            update1.set(flag,dayDataEntityCount.getIqiyiH5()-dayDataEntity1.getIqiyiH5()+staticeEntity.getV9());
            update.set(flag,staticeEntity.getV9());
        }

        fourthMongoTemplate.updateFirst(new Query(Criteria.where("_id").is(dayDataEntity1.getId())),update, "day_data");
        fourthMongoTemplate.updateFirst(new Query(Criteria.where("_id").is(dayDataEntityCount.getId())),update1, "day_data");

    }

    @Override
    public void updateYoulianghui(DayDataEntity dayDataEntity) {
        Update update = new Update();
        update.set("youlianghui",dayDataEntity.getYoulianghui());
        fourthMongoTemplate.updateFirst(new Query(Criteria.where("id").is(dayDataEntity.getId())),update, DayDataEntity.class);
    }

    @Override
    public Map monthData(MonthDataEntity monthDataEntity, Pageable pageable) {
        Query query = new Query();
        query.skip((pageable.getPageNumber())*pageable.getPageSize());
        query.limit(pageable.getPageSize());
        Criteria criteria = new Criteria();

        if (monthDataEntity.getQTime()!=null){
            criteria.andOperator(
                    Criteria.where("time").gte(monthDataEntity.getQTime().get(0).getTime()/1000).lte(monthDataEntity.getQTime().get(1).getTime()/1000)
            );
        }
        query.addCriteria(criteria);
        query.with( Sort.by(Sort.Direction.DESC,new String[]{"time"}));
        List<MonthDataEntity> list = mongoTemplate.find(query, MonthDataEntity.class);
        long total = mongoTemplate.count(query, MonthDataEntity.class);

        Map map =new HashMap();
        map.put("list",list);
        map.put("total",total);
        return map;
    }

    @Override
    public Map monthInfo(MonthInfo monthInfo, Pageable pageable){
        Page<MonthInfo> page = new Page<>(pageable.getPageNumber()+1,pageable.getPageSize());
        QueryWrapper<MonthInfo> wrapper =new QueryWrapper<>();
        if(monthInfo.getQTime()!=null){
            wrapper.ge("time",monthInfo.getQTime().get(0).getTime()/1000);
            wrapper.le("time",monthInfo.getQTime().get(1).getTime()/1000);
        }
        wrapper.orderBy(true,false,"time");
        IPage<MonthInfo> ipage = monthInfoMapper.selectPage(page,wrapper);
        List<MonthInfo> list = ipage.getRecords();
        long total = ipage.getTotal();
        Map map =new HashMap();
        map.put("list",list);
        map.put("total",total);
        return map;
    }

    @Override
    public void getCurrentMonthData() {
        long beginTime = DateUtil.getBeginDayOfMonth().getTime()/1000;
        long endTime = DateUtil.getEndDayOfMonth().getTime()/1000;

        MonthDataEntity monthDataEntity = new MonthDataEntity();
        monthDataEntity.setTime(DateUtil.getBeginDayOfMonth().getTime()/1000);
        //红中麻将充值统计
        //红中麻将充值统计
        Criteria criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time_end").gte(beginTime)
                , Criteria.where("time_end").lt(endTime)
        );
        Aggregation aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        AggregationResults<OrderEntity> ar ;
        AggregationResults<OrderEntity> ar2 ;
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        ar2 = fiveMongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        List<OrderEntity> list = ar.getMappedResults();
        List<OrderEntity> list2= ar2.getMappedResults();
        double totalFee = 0;
        if (list.size()>0){
            totalFee =  list.get(0).getTotalFee();
        }
        monthDataEntity.setXlAllMoney(totalFee/100);
        totalFee=0;
        if (list2.size()>0){
            totalFee = list2.get(0).getTotalFee();
        }
        monthDataEntity.setClAllMoney(totalFee/100);
        monthDataEntity.setAllMoney(monthDataEntity.getXlAllMoney()+monthDataEntity.getClAllMoney());

        //红中麻将苹果充值统计

        totalFee =getTotalFee(beginTime,endTime,"os","ios","order","xlmj","no");
        totalFee +=getTotalFee(beginTime,endTime,"os","ios","order","clmj","no");
        monthDataEntity.setAppleHzmjMoney(totalFee/100);


        //红中麻将安卓充值统计
        totalFee =getTotalFee(beginTime,endTime,"os","android","order","xlmj","no");
        totalFee +=getTotalFee(beginTime,endTime,"os","android","order","clmj","no");
        monthDataEntity.setAndroidHzmjMoney(totalFee/100);

        //红中麻将电脑端充值统计
        totalFee =getTotalFee(beginTime,endTime,"os","pc","order","xlmj","no");
        totalFee +=getTotalFee(beginTime,endTime,"os","pc","order","clmj","no");
        monthDataEntity.setPcHzmjMoney(totalFee/100);


        totalFee =getTotalFee(beginTime,endTime,"channel","_7k7k","order","xlmj","yes");
        monthDataEntity.setSevenkpay(totalFee / 100);

        //红中麻将QQ充值统计
        //红中麻将QQ_minigame_pay统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_qq","order","xlmj","yes");
        monthDataEntity.setQqMiniGamePay(totalFee / 100);

        //红中麻将iqiyi统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_iqiyi","order","xlmj","yes");
        monthDataEntity.setIqiyiPay(totalFee / 100);

        //红中麻将美团统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_meituan$","order","xlmj","yes");
        monthDataEntity.setMeituanPay(totalFee / 100);

        //美团红包版
        totalFee =getTotalFee(beginTime,endTime,"channel","_meituan_re","order","xlmj","yes");
        monthDataEntity.setMeituanRePay(totalFee / 100);

        //微信小游戏充值统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_wechat","order","xlmj","yes");
        totalFee +=getTotalFee(beginTime,endTime,"channel","_wechat","order","clmj","yes");
        monthDataEntity.setWxMiniGamePay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","_ljf","order","xlmj","yes");
        monthDataEntity.setLfjpay(totalFee / 100);

        //顺网充值统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_swjoy","order","xlmj","yes");
        monthDataEntity.setSwjoyPay(totalFee / 100);

        //vivo充值统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_vivo$","order","xlmj","yes");
        monthDataEntity.setVivoPay(totalFee / 100);

        totalFee =getTotalFee(beginTime,endTime,"channel","_tvcoocaa","order","xlmj","yes");
        monthDataEntity.setTvcoocaapay(totalFee / 100);

        totalFee =getTotalFee(beginTime,endTime,"channel","_tvhisense","order","xlmj","yes");
        monthDataEntity.setTvhisensepay(totalFee / 100);

        totalFee =getTotalFee(beginTime,endTime,"channel","_tvhuan","order","xlmj","yes");
        monthDataEntity.setTvhuanpay(totalFee / 100);

        //vivoad包充值统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_vivoad","order","xlmj","yes");
        monthDataEntity.setVivoAdPay(totalFee / 100);

        //闪电玩充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_sdwh5","order","xlmj","yes");
        monthDataEntity.setSdwpay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","_mmy","order","xlmj","yes");
        monthDataEntity.setMmypay(totalFee / 100);

        //小米充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_xiaomi","order","xlmj","yes");
        monthDataEntity.setMipay(totalFee / 100);

        //彩票充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_500caipiao","order","xlmj","yes");
        monthDataEntity.setCaipiaopay(totalFee / 100);

        //苹果渠道充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_apple","order","xlmj","yes");
        monthDataEntity.setApplepay(totalFee / 100);

        //2345充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_game2345","order","xlmj","yes");
        monthDataEntity.setA2345pay(totalFee / 100);

        //迅雷充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_xunlei","order","xlmj","yes");
        monthDataEntity.setXunleipay(totalFee / 100);

        //百度充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_baidu","order","xlmj","yes");
        monthDataEntity.setBaidupay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","^(?!h5).*_huawei","order","xlmj","yes");
        monthDataEntity.setHuaweipay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","h5.*_huawei","order","xlmj","yes");
        monthDataEntity.setHuaweih5pay(totalFee / 100);

        //红中麻将oppoH5统计
        totalFee =getTotalFee(beginTime,endTime,"channel","h5.*_oppo","order","xlmj","yes");
        monthDataEntity.setOppoPay(totalFee / 100);

        //红中麻将oppoMb统计
        totalFee =getTotalFee(beginTime,endTime,"channel","^(?!h5).*_oppo","order","xlmj","yes");
        monthDataEntity.setOppoMbPay(totalFee / 100);


        //红中麻将奇趣统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_quick","order","xlmj","yes");
        monthDataEntity.setQuickpay(totalFee / 100);

        //红中麻将jd统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_jd","order","xlmj","yes");
        monthDataEntity.setJdPay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","_tiktok","order","xlmj","yes");
        monthDataEntity.setDouyinpay(totalFee / 100);

        //红中麻将自营统计
        //  monthDataEntity.setOfficial(totalFee / 100);

        //红中麻将米兰吧统计

        //  monthDataEntity.setMilanbarpay(totalFee / 100);


        //红中麻将月活跃
        criteria = new Criteria();
        criteria.andOperator(Criteria.where("last_time").gte(beginTime).lt(endTime));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        ar2 = fiveMongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        list2 = ar2.getMappedResults();
        int count = 0;
        if (list.size()>0){
            count =  list.get(0).getCount().intValue();
        }
        monthDataEntity.setXlMonthActivity(count);
        count = 0;
        if (list2.size()>0){
            count =  list2.get(0).getCount().intValue();
        }
        monthDataEntity.setClMonthActivity(count);
        monthDataEntity.setMonthActivity(monthDataEntity.getXlMonthActivity()+monthDataEntity.getClMonthActivity());

        //红中麻将苹果月活跃
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("last_time").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("ios")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setIosActivity(count);

        //红中麻将安卓月活跃
        criteria = new Criteria();
        criteria.and("last_time").gte(beginTime).lt(endTime);
        criteria.and("os").is("android");

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setAndroidActivity(count);

        //红中麻将pc月活跃
        criteria = new Criteria();
        criteria.and("last_time").gte(beginTime).lt(endTime);
        criteria.and("os").is("pc");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setPcActivity(count);

        //红中麻将月新增用户
        criteria = new Criteria();
        criteria.andOperator(Criteria.where("reg_time").gte(beginTime).lt(endTime));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        ar2 = fiveMongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        list2 = ar2.getMappedResults();
        count = 0;
        if (list.size()>0){
            count = list.get(0).getCount().intValue();
        }
        monthDataEntity.setXlNewUserCount(count);
        count = 0;
        if (list2.size()>0){
            count = list2.get(0).getCount().intValue();
        }
        monthDataEntity.setClNewUserCount(count);
        monthDataEntity.setNewUserCount(monthDataEntity.getXlNewUserCount()+monthDataEntity.getClNewUserCount());

        //红中麻将苹果月新增用户
        criteria = new Criteria();
        criteria.and("reg_time").gte(beginTime).lt(endTime);
        criteria.and("os").is("ios");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setIosnewUser(count);

        //红中麻将安卓月新增用户
        criteria = new Criteria();
        criteria.and("reg_time").gte(beginTime).lt(endTime);
        criteria.and("os").is("android");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setAndroidnewUser(count);

        //红中麻将pc月新增用户
        criteria = new Criteria();
        criteria.and("reg_time").gte(beginTime).lt(endTime);
        criteria.and("os").is("pc");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setPcUserCount(count);

        //穿山甲

        double pangolin=0;
        pangolin=getAdTotalFee(beginTime, endTime,"channel","totalcl","pangolin","day_data");
        monthDataEntity.setAdClMoney(pangolin);
        pangolin+=getAdTotalFee(beginTime, endTime,"channel","total","pangolin","day_data");
        monthDataEntity.setPangolin(pangolin);

        //优量汇
        pangolin=getAdTotalFee(beginTime, endTime,"channel","totalcl","youlianghui","day_data");
        monthDataEntity.setAdClMoney(pangolin+monthDataEntity.getAdClMoney());
        pangolin+=getAdTotalFee(beginTime, endTime,"channel","total","youlianghui","day_data");
        monthDataEntity.setYoulianghui(pangolin);

        //vivo

        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","vivo","day_data");
        monthDataEntity.setVivo(pangolin);

        //vivoAd
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","vivoAd","day_data");
        monthDataEntity.setVivoAd(pangolin);

        //mi
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","mi","day_data");
        monthDataEntity.setMi(pangolin);

        //huawei
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","huawei","day_data");

        monthDataEntity.setHuawei(pangolin);

        //iOS
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","iOS","day_data");
        monthDataEntity.setIOS(pangolin);

        //oppo
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","oppo","day_data");
        monthDataEntity.setOppo(pangolin);

        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","mmy","day_data");
        monthDataEntity.setMmy(pangolin);

        //oppoH5
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","oppoH5","day_data");
        monthDataEntity.setOppoH5(pangolin);
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","sevenk","day_data");
        monthDataEntity.setSevenk(pangolin);
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","iqiyiH5","day_data");
        monthDataEntity.setIqiyiH5(pangolin);


        //oppoH5
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","chuanshanjia","day_data");
        monthDataEntity.setChuanshanjia(pangolin);
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","douyin","day_data");
        monthDataEntity.setDouyin(pangolin);

        monthDataEntity.setAdMoney(monthDataEntity.getPangolin()+monthDataEntity.getYoulianghui()+monthDataEntity.getVivo()+monthDataEntity.getVivoAd()+monthDataEntity.getOppoH5()+monthDataEntity.getIOS()+monthDataEntity.getHuawei()+monthDataEntity.getMi()+monthDataEntity.getOppo()+monthDataEntity.getChuanshanjia()+monthDataEntity.getDouyin()+monthDataEntity.getSevenk()+monthDataEntity.getMmy()+monthDataEntity.getIqiyiH5());
        monthDataEntity.setAdXlMoney(monthDataEntity.getAdMoney()-monthDataEntity.getAdClMoney());
        fourthMongoTemplate.remove(new Query(Criteria.where("time").is(monthDataEntity.getTime())), MonthDataEntity.class);
        fourthMongoTemplate.insert(monthDataEntity);
    }


    private double getTotalFee(Long beginTime,Long endTime,String theKey,String theValue,String collectionName,String channel,String like){
        Criteria criteria = new Criteria();
        criteria.and("time_end").gte(beginTime).lt(endTime);
        if(like.equals("no")) {
            criteria.and(theKey).is(theValue);
        }else {
            criteria.and(theKey).regex(theValue);
        }
        Aggregation aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        AggregationResults<OrderEntity> ar ;
        if(channel.equals("xlmj")){
        ar= mongoTemplate.aggregate(aggregation, collectionName, OrderEntity.class);
        }else {
            ar= fiveMongoTemplate.aggregate(aggregation, collectionName, OrderEntity.class);
        }
        List<OrderEntity> list = ar.getMappedResults();
        double totalFee = 0;
        if (list.size()>0){
            totalFee = list.get(0).getTotalFee();
        }
        return totalFee;
    }

    private Double getAdTotalFee(Long beginTime,Long endTime,String theKey,String theValue,String adName,String collectionName){
        Criteria  criteria = new Criteria();
        criteria.and("time").gte(beginTime).lte(endTime);
        criteria.and(theKey).is(theValue);
        Aggregation aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum(adName).as("pangolin")
        );
        AggregationResults<DayDataEntity> ar1 = mongoTemplate.aggregate(aggregation, collectionName, DayDataEntity.class);
        List<DayDataEntity> list1 = ar1.getMappedResults();
        double pangolin=0;
        if (list1.size()>0){
            pangolin = list1.get(0).getPangolin();
        }
        return pangolin;
    }

    @Override
    public void getLastMonthData() {

        long beginTime = DateUtil.getBeginDayOfLastMonth().getTime()/1000;
        long endTime = DateUtil.getEndDayOfLastMonth().getTime()/1000;
        MonthDataEntity monthDataEntity = new MonthDataEntity();
        monthDataEntity.setTime(beginTime);

        //红中麻将充值统计
        Criteria criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("time_end").gte(beginTime)
                , Criteria.where("time_end").lt(endTime)
        );
        Aggregation aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().sum("total_fee").as("totalFee")
        );
        AggregationResults<OrderEntity> ar ;
        AggregationResults<OrderEntity> ar2 ;
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        ar2 = fiveMongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        List<OrderEntity> list = ar.getMappedResults();
        List<OrderEntity> list2= ar2.getMappedResults();
        double totalFee = 0;
        if (list.size()>0){
            totalFee =  list.get(0).getTotalFee();
        }
        monthDataEntity.setXlAllMoney(totalFee/100);
        totalFee=0;
        if (list2.size()>0){
            totalFee = list2.get(0).getTotalFee();
        }
        monthDataEntity.setClAllMoney(totalFee/100);
        monthDataEntity.setAllMoney(monthDataEntity.getXlAllMoney()+monthDataEntity.getClAllMoney());

        //红中麻将苹果充值统计

        totalFee =getTotalFee(beginTime,endTime,"os","ios","order","xlmj","no");
        totalFee +=getTotalFee(beginTime,endTime,"os","ios","order","clmj","no");
        monthDataEntity.setAppleHzmjMoney(totalFee/100);


        //红中麻将安卓充值统计
        totalFee =getTotalFee(beginTime,endTime,"os","android","order","xlmj","no");
        totalFee +=getTotalFee(beginTime,endTime,"os","android","order","clmj","no");
        monthDataEntity.setAndroidHzmjMoney(totalFee/100);

        //红中麻将电脑端充值统计
        totalFee =getTotalFee(beginTime,endTime,"os","pc","order","xlmj","no");
        totalFee +=getTotalFee(beginTime,endTime,"os","pc","order","clmj","no");
        monthDataEntity.setPcHzmjMoney(totalFee/100);


        totalFee =getTotalFee(beginTime,endTime,"channel","_7k7k","order","xlmj","yes");
        monthDataEntity.setSevenkpay(totalFee / 100);

        //红中麻将QQ充值统计
        //红中麻将QQ_minigame_pay统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_qq","order","xlmj","yes");
        monthDataEntity.setQqMiniGamePay(totalFee / 100);

        //红中麻将iqiyi统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_iqiyi","order","xlmj","yes");
        monthDataEntity.setIqiyiPay(totalFee / 100);

        //红中麻将美团统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_meituan$","order","xlmj","yes");
        monthDataEntity.setMeituanPay(totalFee / 100);

        //美团红包版
        totalFee =getTotalFee(beginTime,endTime,"channel","_meituan_re","order","xlmj","yes");
        monthDataEntity.setMeituanRePay(totalFee / 100);

        //微信小游戏充值统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_wechat","order","xlmj","yes");
        totalFee +=getTotalFee(beginTime,endTime,"channel","_wechat","order","clmj","yes");
        monthDataEntity.setWxMiniGamePay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","_ljf","order","xlmj","yes");
        monthDataEntity.setLfjpay(totalFee / 100);

        //顺网充值统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_swjoy","order","xlmj","yes");
        monthDataEntity.setSwjoyPay(totalFee / 100);

        //vivo充值统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_vivo$","order","xlmj","yes");
        monthDataEntity.setVivoPay(totalFee / 100);

        totalFee =getTotalFee(beginTime,endTime,"channel","_tvcoocaa","order","xlmj","yes");
        monthDataEntity.setTvcoocaapay(totalFee / 100);

        totalFee =getTotalFee(beginTime,endTime,"channel","_tvhisense","order","xlmj","yes");
        monthDataEntity.setTvhisensepay(totalFee / 100);

        totalFee =getTotalFee(beginTime,endTime,"channel","_tvhuan","order","xlmj","yes");
        monthDataEntity.setTvhuanpay(totalFee / 100);

        //vivoad包充值统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_vivoad","order","xlmj","yes");
        monthDataEntity.setVivoAdPay(totalFee / 100);

        //闪电玩充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_sdwh5","order","xlmj","yes");
        monthDataEntity.setSdwpay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","_mmy","order","xlmj","yes");
        monthDataEntity.setMmypay(totalFee / 100);

        //小米充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_xiaomi","order","xlmj","yes");
        monthDataEntity.setMipay(totalFee / 100);

        //彩票充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_500caipiao","order","xlmj","yes");
        monthDataEntity.setCaipiaopay(totalFee / 100);

        //苹果渠道充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_apple","order","xlmj","yes");
        monthDataEntity.setApplepay(totalFee / 100);

        //2345充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_game2345","order","xlmj","yes");
        monthDataEntity.setA2345pay(totalFee / 100);

        //迅雷充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_xunlei","order","xlmj","yes");
        monthDataEntity.setXunleipay(totalFee / 100);

        //百度充值
        totalFee =getTotalFee(beginTime,endTime,"channel","_baidu","order","xlmj","yes");
        monthDataEntity.setBaidupay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","^(?!h5).*_huawei","order","xlmj","yes");
        monthDataEntity.setHuaweipay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","h5.*_huawei","order","xlmj","yes");
        monthDataEntity.setHuaweih5pay(totalFee / 100);

        //红中麻将oppoH5统计
        totalFee =getTotalFee(beginTime,endTime,"channel","h5.*_oppo","order","xlmj","yes");
        monthDataEntity.setOppoPay(totalFee / 100);

        //红中麻将oppoMb统计
        totalFee =getTotalFee(beginTime,endTime,"channel","^(?!h5).*_oppo","order","xlmj","yes");
        monthDataEntity.setOppoMbPay(totalFee / 100);


        //红中麻将奇趣统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_quick","order","xlmj","yes");
        monthDataEntity.setQuickpay(totalFee / 100);

        //红中麻将jd统计
        totalFee =getTotalFee(beginTime,endTime,"channel","_jd","order","xlmj","yes");
        monthDataEntity.setJdPay(totalFee / 100);


        totalFee =getTotalFee(beginTime,endTime,"channel","_tiktok","order","xlmj","yes");
        monthDataEntity.setDouyinpay(totalFee / 100);

        //红中麻将自营统计
      //  monthDataEntity.setOfficial(totalFee / 100);

        //红中麻将米兰吧统计

      //  monthDataEntity.setMilanbarpay(totalFee / 100);


        //红中麻将月活跃
        criteria = new Criteria();
        criteria.andOperator(Criteria.where("last_time").gte(beginTime).lt(endTime));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        ar2 = fiveMongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        list2 = ar2.getMappedResults();
        int count = 0;
        if (list.size()>0){
            count =  list.get(0).getCount().intValue();
        }
        monthDataEntity.setXlMonthActivity(count);
        count = 0;
        if (list2.size()>0){
            count =  list2.get(0).getCount().intValue();
        }
        monthDataEntity.setClMonthActivity(count);
        monthDataEntity.setMonthActivity(monthDataEntity.getXlMonthActivity()+monthDataEntity.getClMonthActivity());

        //红中麻将苹果月活跃
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("last_time").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("ios")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setIosActivity(count);

        //红中麻将安卓月活跃
        criteria = new Criteria();
        criteria.and("last_time").gte(beginTime).lt(endTime);
        criteria.and("os").is("android");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setAndroidActivity(count);

        //红中麻将pc月活跃
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("last_time").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("pc")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setPcActivity(count);

        //红中麻将月新增用户
        criteria = new Criteria();
        criteria.andOperator(Criteria.where("reg_time").gte(beginTime).lt(endTime));
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        ar2 = fiveMongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        list2 = ar2.getMappedResults();
        count = 0;
        if (list.size()>0){
            count = list.get(0).getCount().intValue();
        }
        monthDataEntity.setXlNewUserCount(count);
        count = 0;
        if (list.size()>0){
            count = list2.get(0).getCount().intValue();
        }
        monthDataEntity.setClNewUserCount(count);
        monthDataEntity.setNewUserCount(monthDataEntity.getXlNewUserCount()+monthDataEntity.getClNewUserCount());

        //红中麻将苹果月新增用户
        criteria = new Criteria();
        criteria.andOperator(
                Criteria.where("reg_time").gte(beginTime).lt(endTime)
                ,Criteria.where("os").is("ios")
        );
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setIosnewUser(count);

        //红中麻将安卓月新增用户
        criteria = new Criteria();
        criteria.and("reg_time").gte(beginTime).lt(endTime);
        criteria.and("os").is("android");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setAndroidnewUser(count);

        //红中麻将pc月新增用户
        criteria = new Criteria();
        criteria.and("reg_time").gte(beginTime).lt(endTime);
        criteria.and("os").is("pc");
        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group().count().as("count")
        );
        ar = mongoTemplate.aggregate(aggregation, "user", OrderEntity.class);
        list = ar.getMappedResults();
        count = 0;
        if (list.size()>0){
            OrderEntity orderEntity = list.get(0);
            count = orderEntity.getCount().intValue();
        }
        monthDataEntity.setPcUserCount(count);

        //穿山甲

        double pangolin=0;
        pangolin=getAdTotalFee(beginTime, endTime,"channel","totalcl","pangolin","day_data");
        monthDataEntity.setAdClMoney(pangolin);
        pangolin+=getAdTotalFee(beginTime, endTime,"channel","total","pangolin","day_data");
        monthDataEntity.setPangolin(pangolin);

        //优量汇
        pangolin=getAdTotalFee(beginTime, endTime,"channel","totalcl","youlianghui","day_data");
        monthDataEntity.setAdClMoney(pangolin+monthDataEntity.getAdClMoney());
        pangolin+=getAdTotalFee(beginTime, endTime,"channel","total","youlianghui","day_data");
        monthDataEntity.setYoulianghui(pangolin);

        //vivo

        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","vivo","day_data");
        monthDataEntity.setVivo(pangolin);

        //vivoAd
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","vivoAd","day_data");
        monthDataEntity.setVivoAd(pangolin);

        //mi
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","mi","day_data");
        monthDataEntity.setMi(pangolin);

        //huawei
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","huawei","day_data");

        monthDataEntity.setHuawei(pangolin);

        //iOS
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","iOS","day_data");
        monthDataEntity.setIOS(pangolin);

        //oppo
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","oppo","day_data");
        monthDataEntity.setOppo(pangolin);

        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","mmy","day_data");
        monthDataEntity.setMmy(pangolin);

        //oppoH5
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","oppoH5","day_data");
        monthDataEntity.setOppoH5(pangolin);
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","sevenk","day_data");
        monthDataEntity.setSevenk(pangolin);
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","iqiyiH5","day_data");
        monthDataEntity.setIqiyiH5(pangolin);


        //oppoH5
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","chuanshanjia","day_data");
        monthDataEntity.setChuanshanjia(pangolin);
        pangolin=getAdTotalFee(beginTime, endTime,"channel","total","douyin","day_data");
        monthDataEntity.setDouyin(pangolin);

        monthDataEntity.setAdMoney(monthDataEntity.getPangolin()+monthDataEntity.getYoulianghui()+monthDataEntity.getVivo()+monthDataEntity.getVivoAd()+monthDataEntity.getOppoH5()+monthDataEntity.getIOS()+monthDataEntity.getHuawei()+monthDataEntity.getMi()+monthDataEntity.getOppo()+monthDataEntity.getChuanshanjia()+monthDataEntity.getDouyin()+monthDataEntity.getSevenk()+monthDataEntity.getMmy()+monthDataEntity.getIqiyiH5());
        monthDataEntity.setAdXlMoney(monthDataEntity.getAdMoney()-monthDataEntity.getAdClMoney());
        //  System.out.println(monthDataEntity);
        fourthMongoTemplate.remove(new Query(Criteria.where("time").is(monthDataEntity.getTime())), MonthDataEntity.class);
        fourthMongoTemplate.insert(monthDataEntity);
    }
}
